package com.eistert.java.datastructure._14_AVL;

import com.eistert.java.datastructure._08_Map._08_Map;
import com.eistert.java.util.FileOperation2;

import java.util.ArrayList;

public class _14_TestMapMain {

    private static double testMap(_08_Map<String, Integer> a14Map, String filename) {

        long startTime = System.nanoTime();

        System.out.println(filename);
        ArrayList<String> words = new ArrayList<>();
        if (FileOperation2.readFile(filename, words)) {
            System.out.println("Total words: " + words.size());

            for (String word : words) {
                if (a14Map.contains(word))
                    a14Map.set(word, a14Map.get(word) + 1);
                else
                    a14Map.add(word, 1);
            }

            System.out.println("Total different words: " + a14Map.getSize());
            System.out.println("Frequency of PRIDE: " + a14Map.get("pride"));
            System.out.println("Frequency of PREJUDICE: " + a14Map.get("prejudice"));
        }

        long endTime = System.nanoTime();

        return (endTime - startTime) / 1000000000.0;
    }

    public static void main(String[] args) {

        String filename = "pride-and-prejudice.txt";

        _14_BSTMap<String, Integer> a14BstMap = new _14_BSTMap<>();
        double time1 = testMap(a14BstMap, filename);
        System.out.println("BST Map: " + time1 + " s");

        System.out.println();

        _14_LinkedList14Map<String, Integer> a14LinkedListMap = new _14_LinkedList14Map<>();
        double time2 = testMap(a14LinkedListMap, filename);
        System.out.println("Linked List Map: " + time2 + " s");

        System.out.println();

        _14_AVLMap<String, Integer> avlMap = new _14_AVLMap<>();
        double time3 = testMap(avlMap, filename);
        System.out.println("AVL Map: " + time3 + " s");
    }
}
